﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CountJobTags {
    /// <summary>
    /// Holds a single Job ID/tag list
    /// </summary>
    /// <remarks>
    /// For example, job 53891 might have tags C#/ASP.NET/JavaScript
    /// </remarks>
    public class JobAndTags {
        /// <summary>Identifies the job</summary>
        public int JobId { get; set; }
        
        /// <summary>All the tags for this job</summary>
        public List<string> Tags { get; set; }

        /// <summary>
        /// Default constructor
        /// </summary>
        public JobAndTags() {
            Tags = new List<string>();
        }

        /// <summary>
        /// Constructor takes an ID and the first tag in use
        /// </summary>
        /// <param name="id">ID to use</param>
        /// <param name="aTag">Tag to start with</param>
        public JobAndTags(string id, string aTag) : this() {
            JobId = int.Parse(id);
            Tags.Add(aTag);
        }

        /// <summary>
        /// Displays the ID with its tags separated by commas
        /// </summary>
        /// <returns></returns>
        public override string ToString() {
            string allTags = Tags.Aggregate("", (p, c) => p + c + ",");
            if (allTags.Length > 1) {
                allTags = allTags.Substring(0, allTags.Length - 1);
            }
            return string.Format("ID: {0}/{1}", JobId, allTags);
        }
    }
}
